-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serialize unit test to prevent flaky failures #2394
Conversation
@@ -134,7 +134,7 @@ func TestAzureMachinePool_Validate(t *testing.T) { | |||
for _, c := range cases { | |||
c := c | |||
t.Run(c.Name, func(t *testing.T) { | |||
t.Parallel() | |||
// Don't add t.Parallel() here or the test will fail. | |||
// NOTE: AzureMachinePool is behind MachinePool feature gate flag; the web hook | |||
// must prevent creating new objects in case the feature flag is disabled. | |||
defer utilfeature.SetFeatureGateDuringTest(t, feature.Gates, capifeature.MachinePool, true)() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this defer be run before the test cases and not in the loop so it is set for all following runs? then removed when this set of cases are done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that (the pattern used in azuremachinepool_webhook_test.go) but it still fails with t.Parallel()
in the loop. So this PR represents the smallest change needed.
I think it is telling that none of our other uses of defer utilfeature.SetFeatureGateDuringTest
use t.Parallel()
, nor do the related unit tests in kubernetes/component-base.
This repro'd for me today: It's not clear (to me) why we didn't see this non-determinism UT outcome earlier... |
This was introduced in #2376 which just merged recently (the test didn't fail on the PR CI itself so it wasn't caught) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jackfrancis The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind failing-test
What this PR does / why we need it:
The parallelized test
TestAzureMachinePool_Validate
callsSetFeatureGateDuringTest
which doesn't appear to be goroutine-safe. Removingt.Parallel()
makes it reliable and does not affect the time the test takes to run.Which issue(s) this PR fixes:
Fixes #2391
Special notes for your reviewer:
TODOs:
Release note: